import logging
from clickhouse_driver import Client
import clickhouse_driver
import datetime
from clickhouse_sqlalchemy import make_session
from sqlalchemy import create_engine


conf = {
    "user": "wuji1626",
    "password": "wuji1626",
    "server_host": "192.168.56.11",
    "port": "9000",
    "db": "9000"
}


class CkClient:
    """数据库连接的公共类，初始化连接，自定义查询，删除等操作"""

    def __init__(self):
        self.host = "192.168.56.11"
        self.port = 9000
        self.user = "wuji1626"
        self.password = "zwh123123"
        self.db = "daily"
        self.connect = clickhouse_driver.connect(user=self.user, password=self.password, host=self.host,
                                                port=self.port, database=self.db).cursor()
        self.resultlist = []
    # def __int__(self):
    #     self.connection = 'clickhouse://{user}:{password}@{server_host}:{port}/{db}'.format(**conf)
    #     self.engine = create_engine(self.connection, pool_size=100, pool_recycle=3600, pool_timeout=20)
    #     self.session = make_session(self.engine)


if __name__ == '__main__':
    ck = CkClient()

    sql = "insert into daily.t_diary (task_name, task_type) values"
    # sql = "select * from t_diary"
    # connection = 'clickhouse://{user}:{password}@{server_host}:{port}/{db}'.format(**conf)
    # engine = create_engine(connection, pool_size=100, pool_recycle=3600, pool_timeout=20)
    # session = make_session(engine)
    # cursor = session.execute(sql)
    datas = [('gggg', '6666'), ('hhhh', '7777')]
    cursor = ck.connect
    res = cursor.executemany(sql, datas)
    print(res)
